import Vue from 'vue'
import App from './App.vue'
import './registerServiceWorker'
import router from './router'
import store from './store'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
// import Axios from 'axios';
import Qs from 'qs';
// import './static/iconfont.css'
import http from './store/http.js';
import echarts from 'echarts';
import './assets/iconfont/iconfont.css';
import Router from 'vue-router'

Vue.prototype.$echarts = echarts;
// Vue.prototype.$axios = Axios;  //默认的axios实例
Vue.prototype.$axios = http;  //自定义axios实例
Vue.prototype.$qs = Qs;

Vue.config.productionTip = false
Vue.use(ElementUI);

router.beforeEach((to, from, next) => {
  console.log(to);
  console.log('进入路由守卫');
  if (to.matched.some(item => item.meta.requiresAuth)) {
    console.log('需要登录验证');
    if (true) {
      console.log('已登录');
      next()
    }else if(store.state.loginState=="false"){
      console.log("未登录")
      next({path:'/'})
    }
  }else{
    console.log("不需要验证")
    next() ; 
  }
})

const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
